<?php


namespace App\Service\WeappToken;


use App\Model\WeappToken;
use Ramsey\Uuid\Uuid;

class App implements WeappTokenInterface
{


    function __construct()
    {

    }


    /**
     * 生成token
     * Create by Peter
     * 2019/12/05 10:39:00
     * Email:904801074@qq.com
     * @param $uid
     * @return string
     * @throws \Exception
     */
    function createToken($uid){

        $uuid=Uuid::uuid1();

        $token=(string)$uuid.$uid;

        return md5($token);

    }


    function saveToken($uid,$type,$expire_time=60*60*24*3){


        $token=$this->createToken($uid);

        WeappToken::create([
            'token'=>$token,
            'user_id'=>$uid,
            'expire_time'=>time()+$expire_time,
            'type'=>$type
        ]);


        return $token;

    }


}
